import CSuperForm from "@/components/CSuperForm/index.vue";
import Ctable from "@/components/Ctable/index.vue";

function onMountedScriptFn(data) {
  return `
  ${data.highEdit.ref}Methods.value = intialFnFn({ obj: intialDataFnClass.obj, intialFn:${data.highEdit.ref}intialFn });`;
}
function templateFn(data) {
  return `
    <CSuperForm v-bind="${data.highEdit.ref}" v-on="${data.highEdit.ref}Methods" />`;
}
function scriptFn(data, type) {
  return `
let ${data.highEdit.ref}intialData: IntialDataType = ${JSON.stringify(data.props)};
let ${data.highEdit.ref} = ref(intialDataFnClass.add(${data.highEdit.ref}intialData, '${type}'));
let ${data.highEdit.ref}intialFn: intialFnType = {
  ${type}: {
    commonFn: [${
      data.highEdit.showAdd
        ? `
      { methodName: "showAdd", other: { refKey: '${data.highEdit.showAdd}'}},`
        : ""
    }${
      data.highEdit.getListFn
        ? `
      { methodName: "getListFn", other: { ${data.highEdit.getListFn ? "refKey:'" + data.highEdit.getListFn : ""}',  ${type == "cSearch" && data.highEdit.ref ? "cSearchKey:'" + data.highEdit.ref : data.highEdit.cSearchKey ? "cSearchKey:'" + data.highEdit.cSearchKey : ""}'}}`
        : ""
    }
    ]
  },
};
let ${data.highEdit.ref}Methods: any = ref({ ${data.highEdit.ref}: {}});`;
}
export default function initContainer(registerConfig) {
  registerConfig.register({
    key: "cSearch",
    type: "container",
    leftOpt: { label: "搜索容器", preview: <CSuperForm cSearchOpt={{}} formType="cSearch" /> },
    middleOpt: { render: <CSuperForm />, props: { cSearchOpt: {}, formType: "cSearch" }, highEdit: { getListFn: "", cSearchKey: "", ref: "cSearch" } },
    rightOpt: {
      settingRender: [
        { type: "input", key: "ref", label: "ref", editType: "high", tip: "自身Ref值" },
        { key: "showAdd", type: "input", label: "showAdd", tip: "新增时所需打开的弹窗Ref值-一般初始值cDio", editType: "high" },
        { key: "getListFn", type: "input", label: "getListFn", tip: "查询时所需搜索的表格Ref值-一般初始值cTable", editType: "high" },
        //{ key: "cSearchKey", type: "input", label: "cSearchKey", tip: "新增后所需搜索的表单Ref值-一般初始值cSearch", editType: "high" },
        { key: "noAdd", propKey: ["cSearchOpt"], type: "radio", label: "noAdd", tip: "不展示新增按钮", editType: "normalProp" },
        { key: "addBtnText", propKey: ["cSearchOpt"], type: "input", label: "addBtnText", tip: "新增按钮的文字展示", editType: "prop" },
        { key: "notdialogAdd", propKey: ["cSearchOpt"], type: "radio", label: "notdialogAdd", tip: "点击新增不打开弹窗", editType: "prop" },
        { key: "newRoute", propKey: ["cSearchOpt"], type: "input", label: "newRoute", tip: "新增按钮跳转页面新增时所需的路径", editType: "prop" },
        { key: "noReset", propKey: ["cSearchOpt"], type: "radio", label: "noReset", tip: "不展示重置按钮", editType: "prop" }
      ]
    },
    headerOpt: {
      template: (data) => templateFn(data),
      script: (data) => scriptFn(data, "cSearch"),
      onMountedScript: (data) => onMountedScriptFn(data)
    }
  });
  registerConfig.register({
    key: "cDio",
    type: "container",
    leftOpt: { label: "弹窗新增容器", preview: <div style={{ fontSize: "12px" }}>弹窗新增容器</div> },
    middleOpt: {
      render: <CSuperForm />,
      props: { formType: "cDio", cformOpt: {} },
      highEdit: { ref: "cDio", getListFn: "" },
      otherProps: { cDioOpt: { open: true } }
    },
    rightOpt: {
      settingRender: [
        { key: "saveUrl", type: "input", label: "saveUrl", propKey: ["cformOpt"], editType: "normalProp", tip: "保存时的接口" },
        { key: "ref", type: "input", label: "ref", editType: "high", tip: "自身Ref值" },
        { key: "getListFn", type: "input", label: "getListFn", tip: "新增后所需搜索的表格Ref值-一般初始值cTable", editType: "high" },
        { key: "cSearchKey", type: "input", label: "cSearchKey", tip: "新增后所需搜索的表单Ref值-一般初始值cSearch", editType: "high" },
        { key: "title", propKey: ["cDioOpt"], type: "input", label: "title", tip: "弹窗标题", editType: "normalProp" },
        // { key: "showAdd", type: "input", label: "showAdd", tip: "新增时所需打开的弹窗Ref值-一般初始值cDio", editType: "high" },
        { key: "width", propKey: ["cDioOpt"], type: "input", label: "width", tip: "弹窗宽度", editType: "prop" },
        { key: "noSubmit", propKey: ["cDioOpt"], type: "radio", label: "noSubmit", tip: "没有确认按钮", editType: "prop" },
        { key: "style", propKey: ["cDioOpt"], type: "input", label: "style", tip: "弹窗样式", editType: "prop" },
        { key: "top", propKey: ["cDioOpt"], type: "input", label: "top", tip: "弹窗离顶部多少距离", editType: "prop" },
        { key: "noFooter", propKey: ["cDioOpt"], type: "radio", label: "noFooter", tip: "没有底部", editType: "prop" },
        { key: "notSaveAfter", propKey: ["cDioOpt"], type: "radio", label: "notSaveAfter", tip: "新增后不需要刷新表格", editType: "prop" },
        { key: "open", propKey: ["cDioOpt"], type: "radio", label: "open", tip: "弹窗是否打开", editType: "prop" }
      ]
    },
    headerOpt: {
      template: (data) => templateFn(data),
      script: (data) => scriptFn(data, "cDio"),
      onMountedScript: (data) => onMountedScriptFn(data)
    }
  });
  registerConfig.register({
    key: "cPage",
    type: "container",
    leftOpt: {
      label: "新增页面容器",
      preview: <CSuperForm formType="cPage" />
    },
    middleOpt: {
      render: <CSuperForm />,
      props: { formType: "cPage", cformOpt: {}, cPageOpt: {} },
      highEdit: { ref: "cPage" }
    },
    rightOpt: {
      settingRender: [
        { type: "input", key: "ref", label: "ref", editType: "high", tip: "自身Ref值" },
        { type: "input", key: "saveUrl", propKey: ["cformOpt"], label: "saveUrl", editType: "normalProp", tip: "保存时的接口" },
        { propKey: ["cPageOpt"], key: "detailUrl", type: "input", label: "detailUrl", tip: "获取详情的接口", editType: "normalProp" },
        { propKey: ["cPageOpt"], key: "saveTxt", type: "input", label: "saveTxt", tip: "新增按钮的展示文字", editType: "normalProp" }
      ]
    },
    headerOpt: {
      template: (data) => templateFn(data),
      script: (data) => scriptFn(data, "cPage"),
      onMountedScript: (data) => onMountedScriptFn(data)
    }
  });
  registerConfig.register({
    key: "cTable",
    type: "container",
    leftOpt: { label: "表格容器", preview: <Ctable cTableOpt={{}} /> },
    middleOpt: { render: <Ctable></Ctable>, highEdit: { ref: "cTable" }, props: { cTableOpt: { list: {} } } },
    rightOpt: {
      settingRender: [
        { type: "input", key: "url", propKey: ["cTableOpt", "delete"], tip: "删除按钮对应的接口", label: "delete-url", editType: "normalProp" },
        { type: "input", propKey: ["cTableOpt", "list"], key: "url", tip: "获取数据的接口", label: "url", editType: "normalProp" },
        { type: "input", propKey: ["cTableOpt", "list"], key: "params", tip: "获取数据的接口尾缀", label: "params", editType: "prop" },
        { type: "radio", propKey: ["cTableOpt"], key: "summary", tip: "是否有合计", label: "summary", editType: "prop" },
        { type: "input", key: "hasChildren", propKey: ["cTableOpt", "treeProps"], tip: "树形时当前列是否有儿子的字段判断", label: "hasChildren", editType: "prop" },
        { type: "input", key: "children", propKey: ["cTableOpt", "treeProps"], tip: "树形时当前列 儿子的字段", label: "children", editType: "prop" },
        { type: "input", key: "rowKey", propKey: ["cTableOpt"], tip: "row中包含children字段去展示树类型结构时所需 默认值是id", label: "rowKey", editType: "prop" },
        { type: "radio", key: "selection", propKey: ["cTableOpt"], tip: "是否有勾选项", label: "selection", editType: "prop" },
        { type: "number", key: "btnWidth", propKey: ["cTableOpt"], tip: "操作栏宽度", label: "btnWidth", editType: "prop" },
        { type: "radio", key: "noBtn", propKey: ["cTableOpt"], tip: "是否隐藏操作栏", label: "noBtn", editType: "normalProp" },
        { type: "radio", key: "hideEdit", propKey: ["cTableOpt"], tip: "是否隐藏编辑按钮", label: "hideEdit", editType: "normalProp" },
        { type: "radio", key: "expand", propKey: ["cTableOpt"], tip: "列表是否可展开", label: "expand", editType: "prop" },
        { type: "radio", key: "noPage", propKey: ["cTableOpt"], tip: "没有pagination区域", label: "noPage", editType: "normalProp" },
        { type: "radio", key: "simplePage", propKey: ["cTableOpt"], tip: "自定义pagination区域内容", label: "simplePage", editType: "prop" },
        { type: "input", key: "pageSizes", propKey: ["cTableOpt"], tip: "表格查询条数配置", label: "pageSizes", editType: "prop" },
        { type: "number", key: "pageSize", propKey: ["cTableOpt"], tip: "默认查询条数", label: "pageSize", editType: "prop" },
        { type: "radio", key: "jumpAdd", propKey: ["cTableOpt"], tip: "编辑是否跳转新页面", label: "jumpAdd", editType: "prop" },
        { type: "input", key: "detailPage", propKey: ["cTableOpt"], tip: "编辑时跳转到新页面的新页面路径", label: "detailPage", editType: "prop" },
        { type: "radio", key: "selectionId", propKey: ["cTableOpt"], tip: "表格勾选时勾选数据是否只放入id", label: "selectionId", editType: "prop" },
        { type: "input", key: "beforeGetList", propKey: ["cTableOpt"], tip: "getListFn发起请求前的数据处理 发起emit('beforeGetListFn', obj, pageSize);", label: "beforeGetList", editType: "prop" },
        { type: "radio", key: "afterGetData", propKey: ["cTableOpt"], tip: "getListFn后是否发起emit('afterGetData', tableData.value)进行返回值的处理", label: "afterGetData", editType: "prop" },
        { type: "radio", key: "noData", propKey: ["cTableOpt"], tip: "加载后不发起请求", label: "noData", editType: "normalProp" },
        { type: "radio", key: "deleteTxt", propKey: ["cTableOpt", "delete"], tip: "删除按钮的文字", label: "delete-deleteTxt", editType: "prop" },
        { type: "input", key: "deleteAfter", propKey: ["cTableOpt", "delete"], tip: "删除后需要emit('deleteAfter')", label: "delete-deleteAfter", editType: "prop" },
        {
          type: "valueKeyList",
          propKey: ["cTableOpt", "release"],
          key: "releaseItem",
          tip: "启用禁用对应的相关信息，有默认值 {state: true, changeMsg: '下架成功', showMsg: '上架', btnType:'primary' },{ state: false, changeMsg: '上架成功', showMsg: '下架', btnType: 'danger' }",
          label: "release-releaseItem",
          editType: "prop",
          valueKeyList: [
            [
              { type: "input", tip: "表格里的值", key: "state", propKey: ["cTableOpt", "release", "releaseItem"], label: "state", editType: "prop" },
              { type: "input", tip: "操作栏按钮点击后展示的提示信息文案", key: "changeMsg", propKey: ["cTableOpt", "release", "releaseItem"], label: "changeMsg", editType: "prop" },
              { type: "input", tip: "操作栏的按钮文案", key: "showMsg", propKey: ["cTableOpt", "release", "releaseItem"], label: "showMsg", editType: "prop" },
              { type: "input", tip: "操作栏按钮的类型", key: "btnType", propKey: ["cTableOpt", "release", "releaseItem"], label: "btnType", editType: "prop" }
            ]
          ]
        },
        { type: "input", key: "props", propKey: ["cTableOpt", "release"], tip: "表格里的字段", label: "props", editType: "prop" },
        { type: "input", key: "url", propKey: ["cTableOpt", "release"], tip: "启用禁用的接口", label: "url", editType: "prop" },
        // { key: "getListFn", type: "input", label: "getListFn", tip: "编辑后所需搜索的表格Ref值-一般初始值cTable", editType: "high" },
        // { key: "cSearchKey", type: "input", label: "cSearchKey", tip: "编辑后所需搜索的表单Ref值-一般初始值cSearch", editType: "high" },
        { key: "showAdd", type: "input", label: "showAdd", tip: "编辑时所需打开的弹窗Ref值-一般初始值cDio", editType: "high" },
        { type: "input", key: "ref", tip: "", label: "自身Ref值", editType: "high" }
      ]
    },
    headerOpt: {
      template: (data) => `
    <Ctable v-bind="${data.highEdit.ref}" v-on="${data.highEdit.ref}Methods" />`,
      script: (data) => `
  let ${data.highEdit.ref}intialData: IntialDataType = {
    cTableOpt: {
      list: { url: "/images" },
      delete: { url: "/images" },
      columns: ${JSON.stringify(data.props[`${data.key}Opt`]?.columns || "[]")}
    }
  };
  let ${data.highEdit.ref} = ref(intialDataFnClass.add(${data.highEdit.ref}intialData, "cTable"));
  let ${data.highEdit.ref}intialFn: intialFnType = {
    cTable: {commonFn: [${data.highEdit.showAdd ? `{ methodName: "showAdd", other: { refKey: '${data.highEdit.showAdd}' } }` : ""}${data.methods?.otherFn ? ",otherFn:data.methods.otherFn" : ""}]},
  };
  let ${data.highEdit.ref}Methods: any = ref({ ${data.highEdit.ref}: {}});`,
      onMountedScript: (data) => onMountedScriptFn(data)
    }
  });
}
